package crp.core.space.app;

import com.qwlabs.lang.C2;
import crp.core.space.domain.services.LocationPathLoader;
import crp.core.space.domain.services.LocationSearcher;
import crp.core.space.domain.services.SpaceSearcher;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;

@ApplicationScoped
public class SpaceService {
    private final Instance<LocationSearcher> locationSearchers;
    private final Instance<SpaceSearcher> spaceSearchers;

    @Inject
    public SpaceService(Instance<LocationSearcher> locationSearchers,
                        Instance<SpaceSearcher> spaceSearchers) {
        this.locationSearchers = locationSearchers;
        this.spaceSearchers = spaceSearchers;
    }

    public LocationSearcher locationSearcher() {
        return locationSearchers.get();
    }

    public SpaceSearcher spaceSearcher() {
        return spaceSearchers.get();
    }

    public LocationPathLoader pathLoader() {
        return new LocationPathLoader(() -> C2.list(locationSearcher().findAll()));
    }
}
